<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="">
    <style></style>
</head>
<body>
    <script src=""></script>
    <script>
        // 声明变量用let，声明常量用const
        // let和const声明的变量，只能在声明的代码块{}中使用
        function fn1(name,age){
            let a = 10;
            console.log(a);
        }
        fn1('zhangsan',18);

        let a = 10;
        if(a>1){
            let b = 20;
            console.log(b);
        }
        // console.log(b)//报错，b未声明
        const fn3 = a => a*6;    
        const fn = (a) => a*6;
        
        const fn2 = (a) => {
            return a*6
        }
        fn();

        // this: 指代调用该函数的对象
        // 全局访问时，this指代window(浏览器中最顶层的对象)
        console.log(this) 
        console.log(11)
        function fn4(){
            console.log(this,'fn4')
        }
        fn4()
        // 对象
        let person = {
            name: "Alice",
            age: 30,
            isStudent: false,
            greet: function(){ // 这是一个方法
                console.log( this, 'person');
            },
            greet2: () => { // 这是一个方法
                console.log( this, 'person2');
            },
            greet3(){ // 这是一个方法
                console.log( this, 'person3');
            },
        };
        person.greet();
        person.greet2();
        person.greet3();
        
        const fn5 = () => {
            console.log(this)
        }
        fn5();
        

        // push、pop、shift、unshift、splice、slice都是改变原数组
        let arr1 = [1,2,3];
        arr1.push(4);
        console.log(arr1);
        // map、filter返回新数组，不改变原数组
        let arr2 = [1,5,3];
        let arr3 = arr2.map(item => item*2);
        console.log(arr2,arr3);
    </script>
</body>
</html>